const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');

const app = express();

// 配置跨域
app.use(cors());

// 配置中间件
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// 导入路由
const homeRoutes = require('./routes/home');
const credentialRoutes = require('./routes/credential');
const userRoutes = require('./routes/user');

// 使用路由
app.use('/api/home', homeRoutes);
app.use('/api/credential', credentialRoutes);
app.use('/api/user', userRoutes);

const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
  console.log(`服务器运行在端口 ${PORT}`);
}); 